<?php

namespace app\admin\controller;

use app\admin\service\UserGroupService;
use support\spark\model\user\UserGroup;
use support\Request;
use support\View;

class UserGroupController extends Curd
{
    /**
     * 获取列表
     */
    public function index()
    {
        if (request()->isAjax()) {
            $userGroupService = new UserGroupService();
            $res = $userGroupService->getList(request()->all());
            return sparkSuccess($res);
        }
        return view('user_group/index');
    }

    /**
     * 添加
     */
    public function add()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $userGroupService = new UserGroupService();
            $res = $userGroupService->addUserGroup($param);
            return sparkSuccess($res);
        }
        return view('user_group/add');
    }
    /**
     * 编辑
     */
    public function edit(Request $request)
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $userGroupService = new UserGroupService();
            $res = $userGroupService->editUserGroup($param);
            return sparkSuccess($res);
        }
        $id = $request->input('id');
        $userGroupModel = new UserGroup();
        View::assign([
            'info' => $userGroupModel->getInfoById($id)
        ]);
        return view('user_group/edit');
    }

    /**
     * 删除
     */
    public function del(Request $request)
    {
        $id = $request->input('id');
        $userGroupModel = new UserGroup();
         $userGroupModel->delById($id);
        return sparkSuccess(dataReturn(0,'删除成功'));
    }
}